-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8362376: Use @Stable annotation in Java FDLIBM implementation #26341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back darcy! A progress list of the required criteria for merging this PR into |
@jddarcy This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 69 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Some small refactorings could be used to make a few non-static arrays static. |
Webrevs
|
The effect of this PR is to make the affected array elements eligible for constant-folding by the JIT. The contract of If we had a frozen (immutable) array feature in the JVM this PR could be formulated using frozen array constants. But we are not there yet. |
Yes; my intention was to allow HotSpot greater leeway to optimize the FDLIBM code. Under my limited performance testing, the change seemed to be performance neutral, but if it shouldn't cause a regression, I'd be comfortable pushing the change. |
The methods directly affected by this update are atan, exp, and sin, cos, tan. The sin, cos, and tan method are affected by the updates to KernelRemPio2 and tan is also directly affected by its own updates. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The arrays at L.2257-2262 could be declared static
and @Stable
as well, and moved outside the method.
@@ -809,6 +814,7 @@ static final class KernelRemPio2 { | |||
|
|||
private static final int init_jk[] = {2, 3, 4, 6}; // initial value for jk |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private static final int init_jk[] = {2, 3, 4, 6}; // initial value for jk | |
@Stable private static final int init_jk[] = {2, 3, 4, 6}; // initial value for jk |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private static final int init_jk[] = {2, 3, 4, 6}; // initial value for jk | |
@Stable | |
private static final int[] init_jk = {2, 3, 4, 6}; // initial value for jk |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed that array on my edit; will add. Thanks.
@@ -451,7 +453,8 @@ static double compute(double x) { | |||
*/ | |||
private static final double | |||
pio4 = 0x1.921fb54442d18p-1, // 7.85398163397448278999e-01 | |||
pio4lo= 0x1.1a62633145c07p-55, // 3.06161699786838301793e-17 | |||
pio4lo= 0x1.1a62633145c07p-55; // 3.06161699786838301793e-17 | |||
@Stable private static final double |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Stable private static final double | |
@Stable | |
private static final double |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These additions look reasonable.
@jddarcy What about the local arrays mentioned in my comment above
|
I think local arrays require more structural changes to the code, which might be why this patch did not include that change. However, note as said in #26355, such conversions are meaningful and would potentially allow performance boosts. |
Right; those were the ones I was referring to when I wrote "Some small refactorings could be used to make a few non-static arrays static." :-) I wanted to just start with the static final arrays, but I could pull those out too in this PR. |
Okay; I took a look at what the code was actually doing and wrote something that avoiding using arrays entirely. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This array unrolling looks right to me.
I'll write a regression test case to make sure. |
Since the refactoring is rather simple, I'm not sure "yet another test" is really needed. But if you are unsure, then please go ahead. |
@Stable | ||
private static final double | ||
T[] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The legacy C‑like array field syntax is confusing in Java, and it’s not used for the @Stable int[]
arrays below.
@Stable | |
private static final double | |
T[] = { | |
@Stable | |
private static final double[] T = { |
Or at least put the T[]
on the same line so that it’s clear why this field has @Stable
, since regular static final double
s are already constant folded and @wenshao’s comment1 confused me on the “Conversation” tab, since it was missing the T[]
there.
@Stable | |
private static final double | |
T[] = { | |
@Stable | |
private static final double T[] = { |
Footnotes
// 1.5}; | ||
// final double DP_H[] = {0.0, | ||
// 0x1.2b80_34p-1}; // 5.84962487220764160156e-01 | ||
final double DP_H1 = 0x1.2b80_34p-1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final double DP_H1 = 0x1.2b80_34p-1; | |
final double DP_H1 = 0x1.2b80_34p-1; |
Re @turbanoff and @ExE-Boss's style fixes: this code is ported from the c code of fdlibm so it has a lot of irregular styles. I think we might look into updating the implementation to be more Java-ish in the future in another patch. |
I'll address the array declaration syntax in the next commit on the PR. While the current state of Fdlibm.java does show its original C lineage, it has already gone through a few passes of getting it closer to idiomatic Java. |
Add
@Stable
to the static final arrays used in the Java port of FDLIBM.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26341/head:pull/26341
$ git checkout pull/26341
Update a local copy of the PR:
$ git checkout pull/26341
$ git pull https://git.openjdk.org/jdk.git pull/26341/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 26341
View PR using the GUI difftool:
$ git pr show -t 26341
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26341.diff
Using Webrev
Link to Webrev Comment